package com.example.project.controller;

import com.example.project.pojo.Result;
import com.example.project.pojo.Three;
import com.example.project.service.ResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
import java.util.List;


@RestController
public class ResultController {

    @Autowired
    ResultService resultService;

    @RequestMapping("/search_math")
    public String math(HttpSession session){
        String mathLostAll = resultService.getMathAll();
        session.setAttribute("mathLostAll",mathLostAll);
        return mathLostAll.toString();
    }

    @RequestMapping(value = "/addResult",method=RequestMethod.POST)
    public String addResult(@RequestBody Result result){
        resultService.addResult(result);
        return "";
    }

    @RequestMapping("/getSumResult")
    public String getSumResult(HttpSession session){
        List<Three> sumResult = resultService.getSumResult();
        session.setAttribute("sumResult",sumResult);
        return sumResult.toString();
    }

    @RequestMapping("/getAllResult")
    public String getAllResult(HttpSession session){
        List<Integer> allResult = resultService.getAllResult();
        session.setAttribute("allResult",allResult);
        return allResult.toString();
    }

    @RequestMapping("/avgAllResult")
    public String avgAllResult(HttpSession session){
        List<Double> avgAllResult = resultService.avgAllResult();
        session.setAttribute("avgAllResult",avgAllResult);
        return avgAllResult.toString();
    }

}
